<template>
  <div class="app-container"
    style="border:1px solid #e6ebf5; width: 96%;margin-left: 2%;padding-left: 0;padding-right: 0;margin-top: 20px;">
    <el-row>
      <!-- 封面信息 -->
      <el-col :span="24">
        <el-card class="box-card" shadow="never" style="border: none;">
          <div slot="header" class="clearfix">
            <span><i class="el-icon-collection-tag"></i>&nbsp;<b>课程信息</b></span>
          </div>
          <el-form :model="courseModel" ref="courseModel" label-width="130px" label-position="right"
            style="width: 90%;">
            <el-row>
              <el-col :span="12">
                <el-form-item label="课程名称" prop="title">
                  {{courseModel.title}}
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="讲师名称" prop="UserName">
                  {{teacherModel.UserName}}
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="课程分类" prop="SubjectName">
                  {{courseModel.SubjectName}}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="课程类型" prop="TeachType">
                  {{courseModel.TeachTypeStr}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="课程封面" prop="CoverUrl">
                  <img :src="courseModel.CoverUrl" class="avatar">
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="讲师头像" prop="HeadPhoto">
                  <img :src="teacherModel.HeadPhoto" class="avatar">
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="课程描述" prop="Description">
                  {{courseModel.Description}}
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="讲师描述" prop="Remark">
                  {{teacherModel.Remark}}
                </el-form-item>
              </el-col> -->
            </el-row>
          </el-form>
          <div style="text-align:right;margin-top: 10px;">
            <el-button type="primary" @click="checkModal" v-if="courseModel.State==2">审核</el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-dialog :visible.sync="checkVisible" :title="'审核课程'" width="60%" top="20vh" :close-on-click-modal="false">

      <el-form :model="checkModel" ref="checkModel" label-position="right" label-width="80px" style="width: 90%;">
        <el-row>
          <el-col :span="24">
            <el-form-item label="审核" prop="Status">
              <el-select v-model="checkModel.Status" filterable placeholder="请选择">
                <el-option v-for="item in checkStatusList" :key="item.id" :label="item.label" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注/原因" prop="Note">
              <el-input type="textarea" :rows="3" v-model="checkModel.Note" placeholder="备注/原因" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div style="text-align:right;">
        <el-button type="danger" @click="checkVisible=false">关闭</el-button>
        <el-button type="primary" @click="confirmCheckCourse">确定</el-button>
      </div>
    </el-dialog>

    <el-row style="margin-top: 20px;">
      <el-card class="box-card" shadow="never" style="border: none;">
        <div slot="header" class="clearfix">
          <span><i class="el-icon-collection-tag"></i>&nbsp;<b>课程内容信息</b></span>
        </div>
        <!-- 封面内容信息 -->
        <el-col :span="10">
          <el-table :data="modelList" style="width: 100%;border:none;border-right:1px solid #e6ebf5;" height="540"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}" row-key="id" default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column prop="title" label="名称" width="800">
              <template slot-scope="scope"> {{ scope.row.title }}</template>
            </el-table-column>
            <el-table-column align="center" width="80" label="操作" fixed="right">
              <template slot-scope="scope">
                <el-button type="text" size="mini" @click="handleEdit(scope)" icon="el-icon-view">查看</el-button>
                <!-- <el-button v-if="scope.row.Level<5" :disabled="scope.row.id.indexOf('id')>-1" type="text" size="mini"
                  @click="handleAdd(scope)" icon="el-icon-plus">添加</el-button>
                <el-button type="text" size="mini" @click="handleDelete(scope)"
                  v-if="scope.row.ParentCSID!='00000000-0000-0000-0000-000000000000'" icon="el-icon-delete">删除
                </el-button>
                <el-button v-if="scope.row.Level==5" :disabled="scope.row.id.indexOf('id')>-1" type="text" size="mini"
                  @click="handleView(scope)" icon="el-icon-view">预览</el-button> -->
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col :span="14">
          <el-card class="box-card" shadow="never" style="border:none;">
            <div class="text item">
              <el-form :model="model" ref="model" label-width="140px" label-position="right">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="名称：" prop="title">
                      {{model.title}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24" v-if="model.Level != 2">
                    <el-form-item label="描述：" prop="Description">
                      {{model.Description}}
                    </el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="model.Level == 2">
                    <el-form-item label="讲师：" prop="UserName">
                      {{model.UserName}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row v-if="model.Level == 2">
                  <el-col :span="12">
                    <el-form-item label="开始时间：" prop="PlanStartTime">
                      {{model.PlanStartTimeStr}}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="结束时间：" prop="PlanEndTime">
                      {{model.PlanEndTimeStr}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row v-show="model.Level==5">
                  <el-col :span="24">
                    <el-form-item label="课件内容：" prop="fileUrl">
                      {{model.fileUrl}}
                      <!-- <CEVideo width="100%" height="510" v-if="model.icon=='mp4'" :src="url">
                      </CEVideo>
                      <iframe id="displayPdfIframe" v-if="model.icon!='mp4' && model.icon!='pdf'" width="100%"
                        height="510" :src="url" frameborder="0"></iframe>
                      <PDFViewer v-if="model.icon=='pdf'" height="510" width="100%" v-bind="{url}"
                        @document-errored="onDocumentErrored">
                      </PDFViewer> -->
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row v-if="model.Level==1" style="margin-left: 100px;">
                  <el-col :span="24">
                    <el-divider content-position="center">附件列表</el-divider>
                  </el-col>
                </el-row>
                <el-row v-if="model.Level==1 && model.TeachType == 'nx'" style="margin-left: 100px;">
                  <el-col :span="24">
                    <el-table :data="model.Files" style="width: 100%;" height="300" border>
                      <el-table-column prop="AttachmentDIsplayName" label="名称">
                        <template slot-scope="scope">{{ scope.row.DisplayName }}</template>
                      </el-table-column>
                      <el-table-column align="center" prop="icon" label="文件后缀">
                        <template slot-scope="scope">{{ scope.row.icon }}</template>
                      </el-table-column>
                      <el-table-column align="center" prop="Size" label="大小">
                        <template slot-scope="scope">{{ scope.row.SizeStr }}</template>
                      </el-table-column>
                      <el-table-column align="center" width="100" label="操作">
                        <template slot-scope="scope">
                          <a :href="scope.row.DownloadUrl" v-if="scope.row.DownloadUrl" target="_blank">
                            <el-button type="text" size="mini" class="el-icon-download">下载</el-button>
                          </a>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
                <el-row v-if="model.Level==1 && model.TeachType == 'jzpx'" style="margin-left: 100px;">
                  <el-col :span="24">
                    <el-table :data="model.JobList" style="width: 100%;" height="400" border>
                      <el-table-column prop="AttachmentDIsplayName" label="名称">
                        <template slot-scope="scope">{{ scope.row.DisplayName }}</template>
                      </el-table-column>
                      <el-table-column align="center" prop="icon" label="文件后缀">
                        <template slot-scope="scope">{{ scope.row.icon }}</template>
                      </el-table-column>
                      <el-table-column align="center" prop="Size" label="大小">
                        <template slot-scope="scope">{{ scope.row.SizeStr }}</template>
                      </el-table-column>
                      <el-table-column align="center" width="100" label="操作">
                        <template slot-scope="scope">
                          <a :href="scope.row.DownloadUrl" v-if="scope.row.DownloadUrl" target="_blank">
                            <el-button type="text" size="mini" class="el-icon-download">下载</el-button>
                          </a>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-col>
                </el-row>
              </el-form>

              <!-- <div style="text-align:right;margin-top: 10px;">
                <el-button type="danger" @click="reset">重置</el-button>
                <el-button type="primary" @click="confirmModel">保存</el-button>
              </div> -->
            </div>
          </el-card>
        </el-col>
      </el-card>

    </el-row>
  </div>
</template>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }
</style>
<script>
  import {
    getCourseSeriesList, getCourseSeriesById,
    addModel, updateModel, deleteModel, getAdminChapterList,
    saveCourseFile, CheckCourse
  } from '@/api/courseseries'
  import { deepClone } from "@/utils";
  import CEVideo from "@/components/video";
  import PDFViewer from "@/components/PDFView/PDFViewer.vue"
  import { getAllTeacherList } from '@/api/user'
  import { getLevelList, addLevel, updateLevel, getLevelListByCourseId } from '@/api/level'
  import { reqGetPapersList, reqPaperQueDetailByPaperId } from '@/api/paper'
  const defaultModel = {
    id: '',
    ParentCSID: '',
    ParentName: '',
    title: '',
    SortNum: '',
    Description: '',
    TeacherId: '',
    LevelId: '',
    LevelName: '',
    PaperIds: [],
    Attachments: [],
    CoverUrl: '',
    SubTitle: '',
    SID: '',
    MainResourceTitle: '',
    MainResourceUrl: '',
    ResSuffix: '',
    MainResourceSize: '',
    SubjectName: '',
    TeachTypeStr: '',
    ApplicantCount: '',
    PlanTime: '',
    PlanStartTime: '',
    PlanEndTime: '',
    PlanStartTimeStr: '',
    PlanEndTimeStr: '',
    PlanStartAndEndTime: '',
    StartTime: '',
    EndTime: '',
    TeachMinute: '',
    TeachMinuteStr: '',
    IsTeach: '',
    IsTeachStr: '',
    Location: '',
    AllowCount: '',
    TeachType: '',
    IsRecommend: '',
    Body: '',
    Creater: '',
    CreateTime: '',
    Level: 1,
    State: '',
    UserID: '',
    UserName: ''
  }
  export default {
    components: { CEVideo, PDFViewer },
    data() {
      return {
        viewModel: {
          page: 1,
          pageSize: 10,
          total: 0,
          Title: '',
          OrderBy: 'ID',//排序字段
          IsAsc: '' //是否升序
        },
        documentError: undefined,
        dialogPaperVisible: false,
        dialogPaperType: '',
        viewPaperVisible: false,
        checkVisible: false,
        videoVisible: false,
        clickPaperTitle: "",
        subPaperTitle: "",
        url: "",
        minSubPaperTitle: "",
        paperData: [],
        fixedPaperData: [],
        defaultProps: {
          children: "children",
          label: "label"
        },
        checkModel: { CSId: '', Status: '', Note: '' },
        model: deepClone(defaultModel),
        teacherModel: {},
        courseModel: deepClone(defaultModel),
        innerModel: { ParentTitle: '', LevelTitle: '', Id: '', ParentId: '', SortNum: 0 },
        innerCourseModel: { ParentTitle: '', LevelTitle: '', Id: '', ParentId: '', SortNum: 0 },
        modelList: [],
        teacherList: [],
        levelList: [],
        courseLevelList: [],
        paperList: [],
        innerCourseVisible: false,
        innerVisible: false,
        oprateLevelVisible: false,
        dialogLevelType: '',
        multipleSelection: [],
        teacheTypeList: ["直播", "录播"],
        checkStatusList: [{ id: 1, label: "不通过" }, { id: 3, label: "通过" }],
        loading: true,
        apiPre: process.env.VUE_APP_BASE_API,
        actionUrl: '',
        mainActionUrl: '',
        courseRules: {
          title: [{ required: true, message: "请输入课程名称", trigger: "blur" }],
          SubTitle: [{ required: true, message: "请输入简介", trigger: "blur" }],
          CoverUrl: [{ required: true, message: "请上传封面", trigger: "blur" }],
          // TeacherId: [{ required: true, message: "请选择讲师", trigger: "blur" }]
        },
        rules: {
          title: [{ required: true, message: "请输入名称", trigger: "blur" }],
          SubTitle: [{ required: true, message: "请输入简介", trigger: "blur" }],
          LevelId: [{ required: true, message: "请选择等级", trigger: "blur" }],
          CoverUrl: [{ required: true, message: "请上传封面", trigger: "blur" }],
          // TeacherId: [{ required: true, message: "请选择讲师", trigger: "blur" }],
          TeachType: [{ required: true, message: "请选择教学类型", trigger: "blur" }]
        },
        innerRules: {
          LevelTitle: [{ required: true, message: "请输入等级名称", trigger: "blur" }],
        },
        id: ''
      }
    },
    computed: { // 计算属性，只要相关联的值没有改变，直接返回，不再进行计算，与方法区别，缓存

    },
    created() {  // 实例创建完成后执行的代码
      this.id = this.$route.params && this.$route.params.id
      this.getList(this.id)
      // this.getAllTeacherList()
      // this.getLevelList()
      // this.reqGetPapersList()
      this.actionUrl = this.apiPre + '/Upload/UploadFiles'
      this.mainActionUrl = this.apiPre + '/Upload/UploadMainFile'
    },
    methods: {
      async getList(id) {
        const res = await getAdminChapterList(id);
        if (res.data) {
          this.modelList = res.data.Course;
          this.teacherModel = res.data.Teacher
          this.courseModel = deepClone(this.modelList[0])
          if (this.modelList[0].children && this.modelList[0].children.length > 0) {
            this.dialogType = 'edit'
            this.model = deepClone(this.modelList[0].children[0])
          }
        }
        this.loading = false;
      },
      async getAllTeacherList() {
        const res = await getAllTeacherList();
        if (res.data) {
          this.teacherList = res.data;
        }
      },
      async reqGetPapersList() {
        const res = await reqGetPapersList();
        if (res.data) {
          this.paperList = res.data.papersList;
        }
      },
      async getLevelList() {
        const res = await getLevelListByCourseId(this.id);
        if (res.data) {
          this.levelList = res.data;
        }
      },
      handleCourseAvatarSuccess(res, file) {//图片上传成功响应方法
        this.courseModel.CoverUrl = res.data;
      },
      beforeCourseAvatarUpload(file) {
        const isImg = file.type === 'image/jpeg' || file.type === 'image/png';
        const isLt2M = file.size / 1024 / 1024 < 4;

        if (!isImg) {
          this.$notify({
            title: "失败",
            message: "上传图片只能是 JPG/JPEG/PNG 格式!",
            type: "error",
            duration: 3000
          });
          return false
        }
        if (!isLt2M) {
          this.$notify({
            title: "失败",
            message: "上传图片大小不能超过 4MB!",
            type: "error",
            duration: 3000
          });
          return false
        }
        return isImg && isLt2M;
      },
      reset() {
        this.$confirm("确认重置?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            this.model = deepClone(defaultModel)
            this.$refs['model'].clearValidate()
          })
          .catch(err => {
            console.error(err);
          });
      },
      resetCourse() {
        this.$confirm("确认重置?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            this.courseModel = deepClone(this.modelList[0])
            this.$refs['courseModel'].clearValidate()
          })
          .catch(err => {
            console.error(err);
          });
      },
      //保存封面信息
      async confirmCourseModel() {
        //如果把验证失败弹出提示代码放在validate里面则不会弹出错误提示，直接走下面的更新操作代码
        var v;
        this.$refs['courseModel'].validate(valid => {
          v = valid;
        });
        if (!v) {
          return false;
        }
        var m = await updateModel(this.courseModel)
        this.id = m.data.ID
        this.courseModel = deepClone(m.data)
        this.getList(this.id)
        this.$notify({
          title: "成功",
          message: "操作成功",
          type: "success",
          duration: 3000
        });
      },
      async confirmModel() {
        //如果把验证失败弹出提示代码放在validate里面则不会弹出错误提示，直接走下面的更新操作代码
        var v;
        this.$refs['model'].validate(valid => {
          v = valid;
        });
        if (!v) {
          return false;
        }
        if (this.model.Level == 5) {
          this.model.DisplayName = this.model.title
          await saveCourseFile(this.model);
        } else {
          const isEdit = this.dialogType === 'edit';
          if (isEdit) {
            await updateModel(this.model);
          } else {
            await addModel(this.model)
          }
        }

        this.getList(this.id)
        this.model = Object.assign({}, defaultModel)
        this.dialogVisible = false;
        this.$notify({
          title: "成功",
          message: "操作成功",
          type: "success",
          duration: 3000
        });
      },
      handleAvatarSuccess(res, file) {//图片上传成功响应方法
        this.model.CoverUrl = res.data;
      },
      beforeAvatarUpload(file) {
        const isImg = file.type === 'image/jpeg' || file.type === 'image/png';
        const isLt2M = file.size / 1024 / 1024 < 4;

        if (!isImg) {
          this.$notify({
            title: "失败",
            message: "上传图片只能是 JPG/JPEG/PNG 格式!",
            type: "error",
            duration: 3000
          });
          return false
        }
        if (!isLt2M) {
          this.$notify({
            title: "失败",
            message: "上传图片大小不能超过 4MB!",
            type: "error",
            duration: 3000
          });
          return false
        }
        return isImg && isLt2M;
      },
      reset() {
        this.model = deepClone(defaultModel)
        this.$refs['model'].clearValidate()
      },
      handleEdit(scope) {
        this.dialogType = 'edit';
        this.model = deepClone(scope.row);
        this.url = this.model.fileUrl
        if (this.model.icon != "pdf" && this.model.icon != "mp4") {
          this.url = "https://view.officeapps.live.com/op/view.aspx?src=" + this.url;
        }
        console.log(this.url)
        this.$nextTick(() => {
          this.$refs['model'].clearValidate() //清空上次的错误验证提示
        });
      },
      checkModal() {
        this.checkVisible = true;
        this.$nextTick(() => {
          this.$refs['checkModel'].clearValidate() //清空上次的错误验证提示
          this.checkModel.CSId = this.courseModel.id
          this.checkModel.Note = ''
          this.checkModel.Status = 1
        });
      },
      async confirmCheckCourse() {
        var v;
        this.$refs['checkModel'].validate(valid => {
          v = valid;
        });
        if (!v) {
          return false;
        }
        this.$confirm("确认提交审核结果?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            await CheckCourse(this.checkModel)
            this.$notify({
              title: "成功",
              message: "操作成功",
              type: "success",
              duration: 3000
            });
            this.checkVisible = false
            this.getList(this.id)
          })
          .catch(err => {
            console.error(err);
          });

      },
      handleView(scope) {
        var m = scope.row
        this.$router.push("/ems/view/" + m.id);
      },
      handleAdd(scope) {
        this.model = Object.assign({}, defaultModel)
        this.$nextTick(() => {
          var timestamp = new Date().getTime();
          var n = 0
          if (scope.row.children)
            n = scope.row.children.length + 1
          else
            scope.row.children = []
          var newChild = { id: 'id' + timestamp, title: '节点' + n, children: [] };
          this.model.ParentName = scope.row.title
          this.model.title = newChild.title
          this.model.ParentCSID = scope.row.id
          this.model.Level = scope.row.Level + 1
          scope.row.children.push(newChild);
          this.$refs['model'].clearValidate() //清空上次的错误验证提示
        })
        this.dialogType = 'new';
      },
      handleAttachSuccess(res, file) {//图片上传成功响应方法
        var fs = res.data.split('/');
        var fn = fs[fs.length - 1]
        var m = this.model.Attachments[this.model.Attachments.length - 1]
        m.AttachmentUrl = res.data
        m.AttachmentDIsplayName = fn
        this.model.Attachments.splice(this.model.Attachments.length - 1, 1, m)
      },
      beforeAttachUpload(file) {
        this.model.Attachments.push({ AttachmentDIsplayName: file.name, AttachmentSize: parseFloat(file.size / 1024).toFixed(2), AttachmentSizeStr: parseFloat(file.size / 1024).toFixed(2) + "KB" })
      },
      handleMainSuccess(res, file) {//资源上传成功响应方法
        this.model.fileUrl = res.data
        this.$notify({
          title: "成功",
          message: "上传成功!",
          type: "success",
          duration: 3000
        });
      },
      beforeFileUpload(file) {
        var fileName = file.name || ''
        var ext = fileName.split('.')[fileName.split('.').length - 1]
        this.model.filename = file.name
        this.model.icon = ext
        this.model.Size = parseInt(file.size / 1024)
      },
      beforeMainUpload(file) {
        var fileName = file.name || ''
        var ext = fileName.split('.')[fileName.split('.').length - 1]
        if (ext !== "doc" && ext !== "docx" && ext !== "xls" && ext !== "xlsx"
          && ext !== "ppt" && ext !== "pptx" && ext !== "pdf" && ext !== "mp4") {
          this.$notify({
            title: "失败",
            message: "上传资源只能是 doc/docx/xls/xlsx/ppt/pptx/pdf/mp4 格式!",
            type: "error",
            duration: 3000
          });
          return false
        }
        // ppt(10MB)，word(10MB)，excel(5MB)
        if (ext == "doc" || ext == "docx" || ext == "ppt" || ext == "pptx") {
          debugger
          if (parseInt(file.size) > parseInt('10485760‬')) {
            this.$notify({
              title: "失败",
              message: "上传word、ppt文件上限为10MB!",
              type: "error",
              duration: 3000
            });
            return false
          }
        }

        if (ext == "xlsx" || ext == "xls") {
          if (parseInt(file.size) > parseInt('5242880')) {
            this.$notify({
              title: "失败",
              message: "上传excel文件上限为5MB!",
              type: "error",
              duration: 3000
            });
            return false
          }
        }
        this.model.MainResourceTitle = file.name
        this.model.ResSuffix = ext
        this.model.MainResourceSize = parseInt(file.size / 1024)
      },
      removeAttach(scope) {
        this.$confirm("确认删除?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            this.model.Attachments.splice(this.model.Attachments.indexOf(scope.row), 1)
            this.$notify({
              title: "成功",
              message: "操作成功",
              type: "success",
              duration: 3000
            });
          })
          .catch(err => {
            console.error(err);
          });
      },
      handleDelete(scope) {
        if (scope.row.children && scope.row.children.length > 0) {
          this.$notify({
            title: "提示",
            message: "请先删除下面的子节点!",
            type: "warning",
            duration: 3000
          });
          return false
        }
        if (scope.row.id.indexOf('id') > -1) {
          this.getList(this.id)
          this.$notify({
            title: "成功",
            message: "操作成功",
            type: "success",
            duration: 3000
          });
          return false
        }
        this.$confirm("确认删除?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
            await deleteModel(scope.row.id);
            this.$notify({
              title: "成功",
              message: "操作成功",
              type: "success",
              duration: 3000
            });
            this.getList(this.id)
          })
          .catch(err => {
            console.error(err);
          });
      },
      choosePaper(rows) {//选择试卷
        this.dialogPaperVisible = true;
        this.$nextTick(() => {
          this.toggleSelection(rows) //选中已关联的试卷
        });
      },
      viewPaper(scope) {//预览试卷
        this.viewPaperVisible = true
        this.seePaperDetail(scope.row)
      },
      async seePaperDetail(row) {
        let result = await reqPaperQueDetailByPaperId(row.paper_id);
        let singleData = result.data.singleData;
        let multipleData = result.data.multipleData;
        let judgeData = result.data.judgeData;
        let fillData = result.data.fillData;
        //初始化数据
        // this.filterText = "";
        this.clickPaperTitle = `试卷详情：${row.paper_name}`;
        this.subPaperTitle = `试卷总分：${
          result.data.total_score
          }分，试卷总题数：${result.data.total_num}道。`;
        this.minSubPaperTitle = `单选题${result.data.single_num}道（每道${
          result.data.paper.single_score
          }分），
      多选题${result.data.multiple_num}道（每道${
          result.data.paper.multiple_score
          }分），
      判断题${result.data.judge_num}道（每道${
          result.data.paper.judge_score
          }分），
      填空题${result.data.fill_num}道（每道${
          result.data.paper.fill_score
          }分）。`;
        this.paperData = [
          {
            id: 1,
            label: "单选题列表",
            children: singleData
          },
          {
            id: 2,
            label: "多选题列表",
            children: multipleData
          },
          {
            id: 3,
            label: "判断题列表",
            children: judgeData
          },
          {
            id: 4,
            label: "填空题列表",
            children: fillData
          }
        ];
      },
      confirmPaper() {//保存选中的试卷
        this.innerCourseModel.PaperIds = this.multipleSelection
        this.dialogPaperVisible = false
      },
      toggleSelection(rows) {
        this.$refs.multipleTable.clearSelection();
        if (rows) {
          rows.forEach(row => {
            var p = this.paperList.filter(p => p.paper_id == row.paper_id)[0]
            this.$refs.multipleTable.toggleRowSelection(p, true);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      // 封面维护等级
      oprateCourseLevel() {
        this.innerCourseVisible = true;
      },
      filterNode(value, data) {
        if (!value) return true
        return data.label.indexOf(value) !== -1
      },
      getNodeData(data) {
        this.dialogCourseLevelType = 'edit';
        this.innerCourseModel = {
          ParentTitle: data.parentTitle, ParentId: data.parentId,
          LevelTitle: data.label, Id: data.value, SortNum: data.SortNum,
          PaperIds: data.PaperIds
        }
        this.$refs['innerCourseModel'].clearValidate()
      },
      addCourseLevel() {
        this.dialogCourseLevelType = 'new';
        if (this.innerCourseModel.Id == '') {
          this.$notify({
            title: "提示",
            message: "请选择等级",
            type: "warning",
            duration: 3000
          });
          return false
        }
        this.innerCourseModel = { ParentTitle: this.innerCourseModel.LevelTitle, ParentId: this.innerCourseModel.Id, LevelTitle: '', Id: '', SortNum: 0, PaperIds: [] }
      },
      addFirstCourseLevel() {
        this.dialogCourseLevelType = 'new';
        this.innerCourseModel = { ParentTitle: '/', ParentId: '', LevelTitle: '', Id: '', SortNum: 0, PaperIds: [] }
      },
      async confirmCourseLevel() {
        var v;
        this.$refs['innerCourseModel'].validate(valid => {
          v = valid;
        });
        if (!v) {
          return false;
        }
        const isEdit = this.dialogCourseLevelType === 'edit';

        if (isEdit) {
          await updateLevel(this.innerCourseModel);
        } else {
          await addLevel(this.innerCourseModel)
        }
        this.getLevelList()
        this.innerCourseModel = { ParentTitle: '', ParentId: '', LevelTitle: '', Id: '', SortNum: 0, PaperIds: [] }
        this.$notify({
          title: "成功",
          message: "操作成功",
          type: "success",
          duration: 3000
        });
      },
      onDocumentErrored(e) {
        this.documentError = e.text;
      }
    }
  }
</script>